



public class Date {
    public int year;
    public int month;
    public int day;



    // 无参构造方法
    public Date(){
        this.year = 1900;
        this.month = 1;
        this.day = 1;
    }
    // 带有三个参数的构造方法
    public Date(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public void printDate(){
        System.out.println(year + "-" + month + "-" + day);
    }

    public static void main(String[] args) {
        Date d = new Date();
        d.printDate();
    }
}




/*
public class Date {
    public int year;
    public int month;
    public int day;
    // 构造方法：
    // 名字与类名相同，没有返回值类型，设置为void也不行
    // 一般情况下使用public修饰
    // 在创建对象时由编译器自动调用，并且在对象的生命周期内只调用一次
    public Date(int year, int month, int day){
        this.year = year;
        this.month = month;
        this.day = day;
        System.out.println("Date(int,int,int)方法被调用了");
    }
    public void printDate(){
        System.out.println(year + "-" + month + "-" + day);
    }
    public static void main(String[] args) {
        // 此处创建了一个Date类型的对象，并没有显式调用构造方法
        Date d = new Date(2021,6,9);
        d.printDate();
    }
}
*/



/*public class Date {

    public int year;
    public int month;
    public int day;
    public void setDay(Date this, int year, int month, int day){
        this.year = year;
        this.month = month;
        this.day = day;
        this.printDate();
    }
    public void printDate(Date this){
        System.out.println(year + "/" + month + "/" + day);
    }

    public static void main(String[] args) {
        Date d1 = new Date();
        d1.setDay(2020,9,15);
        //d1.printDate();

        *//*Date d2 = new Date();
        d2.setDay(2020,9,16);
        d2.printDate();*//*
    }

    *//*public static void main(String[] args) {
        Date date = new Date();
        date.setDay(2020,9,15);
        date.printDate();
    }*//*


    *//*public static void main(String[] args) {
        // 构造三个日期类型的对象 d1 d2 d3
        Date d1 = new Date();
        Date d2 = new Date();
        Date d3 = new Date();
        // 对d1，d2，d3的日期设置
        d1.setDay(2020,9,15);
        d2.setDay(2020,9,16);
        d3.setDay(2020,9,17);
        // 打印日期中的内容
        d1.printDate();
        d2.printDate();
        d3.printDate();
    }*//*
}*/

